package cz.cuni.mff.ufal.httpserver.protocol;

/**
 * Supported methods of an HTTP request.
 * 
 * @author Bartłomiej Etenkowski
 */
public enum HttpMethod {
  GET("GET"),
  POST("POST"),
  HEAD("HEAD"),
  PUT("PUT"),
  DELETE("DELETE"),
  OPTIONS("OPTIONS"),
  TRACE("TRACE"),
  CONNECT("CONNECT");

  private String str;

  private HttpMethod(String str) {
    this.str = str;
  }

  @Override
  public String toString() {
    return str;
  }

  /**
   * Retrieves the method by its string representation.
   * @param str The string representation of as method.
   * @return The method if the string representation is correct, null otherwise.
   */
  public static HttpMethod parse(String str) {
    for (HttpMethod m : values()) {
      if (m.str.equals(str)) {
        return m;
      }
    }
    return null;
  }
}